<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-04-20
 * Time: 15:49
 */

namespace app\base\controller;

use app\base\model;
use think\Db;

/**
 * 系统设置
 * Class Setting
 * @package app\Base\controller
 */
class Setting extends Common
{
    /**
     * 查看
     * @return mixed
     */
    public function index(){
        $role_id = session('role.id');
        $where = '';
        if($role_id != 1){
            $role_id = explode(',',$role_id);
            $where = [] ;
            foreach($role_id as $k => $v){
                array_push($where,['' ,'EXP',Db::raw('find_in_set("'.$v.'",`role_ids`)')]);
            }
            array_push($where,['role_ids','=','0']);
        }

        //只显示对应权限以及未分配权限的 设置分组
        $setting_tab = Db::name('setting_group')
            ->whereOr($where)
            ->field('id,group_name,form_id')->select();

        foreach($setting_tab as $k => $v){
            $setting_tab[$k]['form'] = get_custom_form($v['form_id']);
        }

        $this->assign('tab',$setting_tab);
        return $this->fetch();
    }

    /**
     * 保存设置
     */
    public function save_setting(){
        $post = input('post.');
        $setDb = new model\Setting();

        $flag = $setDb->_save($post);

        $flag ? $this->success('操作成功'):$this->error('操作失败');
    }


}